//
//  ViewControllerB.m
//  Navi
//
//  Created by student on 16/2/25.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewControllerB.h"
#import "ViewControllerA.h"
#import "ViewControllerC.h"
#import "ViewControllerD.h"
@interface ViewControllerB ()

@end

@implementation ViewControllerB

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    //导航栏的设置
    //左侧按钮
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:nil action:nil];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    //中间标题
    UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"帅",@"很帅"]];
    seg.frame = CGRectMake(0, 0, 100, 50);
    self.navigationItem.titleView = seg;
    
    //右侧按钮
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:nil action:nil];
    self.navigationItem.rightBarButtonItem = rightItem;
}

- (IBAction)pushA:(id)sender
{
    ViewControllerA *vcA = [[ViewControllerA alloc] init];
    [self.navigationController pushViewController:vcA animated:YES];
    
}

- (IBAction)pushB:(id)sender
{
    ViewControllerB *vcB = [[ViewControllerB alloc] init];
    [self.navigationController pushViewController:vcB animated:YES];
}

- (IBAction)pushC:(id)sender
{
    ViewControllerC *vcC = [[ViewControllerC alloc] init];
    [self.navigationController pushViewController:vcC animated:YES];
}

- (IBAction)pushD:(id)sender
{
    ViewControllerD *vcD = [[ViewControllerD alloc] init];
    [self.navigationController pushViewController:vcD animated:YES];
}

- (IBAction)pop:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)popToLevel2:(id)sender
{
    //弹出到指定页面
    // viewControllers 导航栏压入的所有视图控制器数组
    if (self.navigationController.viewControllers.count>2)
    {
        [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];
    }
}


- (IBAction)popToRoot:(id)sender
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

@end
